<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class beranda extends INSP_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('ctrlpnl/model_admin');
	}
	
	
	function index() {
		if ($this->session->userdata('logged_in') == TRUE) {
			$data['base_url'] = base_url();	
			$data['module']	 = 'beranda-home-admin';
			$data['totalposting'] = $this->totalposting('totalsemua');
			$data['totalpostinganda'] = $this->totalposting('totalanda');
			$this->load->view('ctrlpnl/vmain',$data);
		} else {
			$baseUrl = base_url();
			redirect($baseUrl.'ctrlpnl');
		}
	}
	
	function totalposting($param=''){
		$html = "";
		$dataposting = $this->model_admin->getData('tb_category2');
		$countposting = count($dataposting);
		
		switch($param){
			case 'totalsemua':
				if($countposting == 0){
					$html = "<center><i>Tidak ada data postingan</i></center>";
				}else{
					foreach($dataposting as $k=>$v){
						$totaldata = $this->model_admin->countposting('postingsemua',$v['category_code']);
						$html .= "<label>".$v['category_name']."</label> : <label style='padding-right:10px;'>".$totaldata->jml."</label><br>"; 
					}
				}
			break;
			case 'totalanda':
				if($countposting == 0){
					$html = "<center><i>Tidak ada data postingan</i></center>";
				}else{
					foreach($dataposting as $k=>$v){
						$totaldata = $this->model_admin->countposting('postinganda',$v['category_code']);
						$html .= "<label>".$v['category_name']."</label> : <label style='padding-right:10px;'>".$totaldata->jml."</label><br>"; 
					}
				}
			break;
		}
		
		return $html;
	}
		
	
}